#include <iostream>
using namespace std;
int logo() {
  char ch;
  string str;
  int dis = 0;
  while (cin >> ch) {
    if (ch == 'F') {
      int x;
      cin >> ch >> x;
      dis += x;
    } else if (ch == 'B') {
      int x;
      cin >> ch >> x;
      dis -= x;
    } else if (ch == 'R') {
      int x;
      char ch;
      //     EPEAT  10   [
      cin >> str >> x >> ch;
      dis += logo() * x;
      // REPEAT 5[FD 100]REPEAT
    } else {  // ']'
      return dis;
    }
  }
  return dis;
}
int main() { cout << abs(logo()) << endl; }